package org.deadline.model.baseapp;

import flexjson.JSONDeserializer;
import flexjson.JSONSerializer;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.deadline.model.config.Enumeration;
import org.hibernate.annotations.Generated;
import org.hibernate.annotations.GenerationTime;
import org.springframework.format.annotation.DateTimeFormat;

@Entity
public class EmailNotification extends BaseEntity  implements Serializable {

    @ManyToOne
    private Principal mailFrom;

    @NotNull
    @Size(min = 2, max = 255)
    private String mailTo;

    @NotNull
    @Size(min = 2, max = 500)
    private String mailCC;

    @NotNull
    @Size(min = 2, max = 255)
    private String subject;

    @NotNull
    @Size(min = 2, max = 2000)
    private String message;

    @NotNull
    @Temporal(TemporalType.TIMESTAMP)
    @DateTimeFormat(style = "M-")
    private Date mailedDate;

    @NotNull
    @Size(min = 2, max = 255)
    private String comment;

    @ManyToOne
    private Enumeration notifyStatus;

	@Id
	@Column(name="id",unique=true,nullable=false)
	@SequenceGenerator(name="email_notification_seq_gen",sequenceName="email_notification_seq")
	@GeneratedValue(generator="email_notification_seq_gen",strategy=GenerationType.TABLE)
	@Generated(GenerationTime.INSERT)
	private Long id;

	
	private static final long serialVersionUID = 1L;

	public Principal getMailFrom() {
        return this.mailFrom;
    }

	public void setMailFrom(Principal mailFrom) {
        this.mailFrom = mailFrom;
    }

	public String getMailTo() {
        return this.mailTo;
    }

	public void setMailTo(String mailTo) {
        this.mailTo = mailTo;
    }

	public String getMailCC() {
        return this.mailCC;
    }

	public void setMailCC(String mailCC) {
        this.mailCC = mailCC;
    }

	public String getSubject() {
        return this.subject;
    }

	public void setSubject(String subject) {
        this.subject = subject;
    }

	public String getMessage() {
        return this.message;
    }

	public void setMessage(String message) {
        this.message = message;
    }

	public Date getMailedDate() {
        return this.mailedDate;
    }

	public void setMailedDate(Date mailedDate) {
        this.mailedDate = mailedDate;
    }

	public String getComment() {
        return this.comment;
    }

	public void setComment(String comment) {
        this.comment = comment;
    }

	public Enumeration getNotifyStatus() {
        return this.notifyStatus;
    }

	public void setNotifyStatus(Enumeration notifyStatus) {
        this.notifyStatus = notifyStatus;
    }

	public String toString() {
        return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
    }

	public String toJson() {
        return new JSONSerializer().exclude("*.class").deepSerialize(this);
    }

	
	public Long getId() {
	    return this.id;
	}

	public void setId(Long id) {
	    this.id = id;
	}

	public static EmailNotification fromJsonToEmailNotification(String json) {
        return new JSONDeserializer<EmailNotification>().use(null, EmailNotification.class).deserialize(json);
    }

	public static String toJsonArray(Collection<EmailNotification> collection) {
        return new JSONSerializer().exclude("*.class").deepSerialize(collection);
    }

	public static Collection<EmailNotification> fromJsonArrayToEmailNotifications(String json) {
        return new JSONDeserializer<List<EmailNotification>>().use(null, ArrayList.class).use("values", EmailNotification.class).deserialize(json);
    }
}
